//
//  DCIMChatListTableViewCell.m
//  xmppBase
//
//  Created by striby on 16/1/12.
//  Copyright © 2016年 com.dc. All rights reserved.
//

#import "DCIMChatListTableViewCell.h"
#import "UIView+Frame.h"
#import "WZLBadgeImport.h"

static const float recentTimeWidth = 80;

static const float recentTimeFontSize = 12;

static const float senderNameFontSize = 18;

static const float recentMessageFontSize = 14;

static const float messageSettingWidth = 25;


@implementation DCIMChatListTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        [self setSelectionStyle:UITableViewCellSelectionStyleNone];
        
        [self initBaseUI];
        
        UIImageView * line = [[UIImageView alloc]initWithFrame:CGRectMake(0, chatListCellHeight-1, DCDeviceWidth, .5)];
        [line setImage:[UIImage imageNamed:@"case_cell_Line"]];
        [self addSubview:line];
    }
    return self;
}

-(void)initBaseUI
{
    _userIconImageView = [[UIImageView alloc]initWithFrame:CGRectMake(chatListCellMargin, chatListCellMargin, chatListCellHeight-2*chatListCellMargin, chatListCellHeight-2*chatListCellMargin)];
    
    [self.contentView addSubview:_userIconImageView];
    

    _recentTime = [[UILabel alloc]initWithFrame:CGRectMake(DCDeviceWidth-recentTimeWidth-chatListCellMargin, chatListCellMargin*1.5, recentTimeWidth, [UIFont systemFontOfSize:recentTimeFontSize].lineHeight)];
    
    _recentTime.font = [UIFont systemFontOfSize:recentTimeFontSize];
    
    _recentTime.textAlignment = NSTextAlignmentRight;
    
    _recentTime.textColor= [UIColor lightGrayColor];
    
    [self.contentView addSubview:_recentTime];
    
    _senderName = [[UILabel alloc]initWithFrame:CGRectMake(_userIconImageView.frame.origin.x+_userIconImageView.bounds.size.width+chatListCellMargin, chatListCellMargin*1.5, DCDeviceWidth-_userIconImageView.bounds.size.width-recentTimeWidth-4*chatListCellMargin, [UIFont systemFontOfSize:senderNameFontSize].lineHeight)];
    
    _senderName.font = [UIFont systemFontOfSize:senderNameFontSize];
    
    _senderName.textAlignment=NSTextAlignmentLeft;
    
    _senderName.textColor= [UIColor blackColor];
    
    [self.contentView addSubview:_senderName];
    
    
    _messageSettingImageView = [[UIImageView alloc]initWithFrame:CGRectMake(DCDeviceWidth-messageSettingWidth-chatListCellMargin, _userIconImageView.frame.origin.y+_userIconImageView.frame.size.height-messageSettingWidth, messageSettingWidth, messageSettingWidth)];
    
    [self.contentView addSubview:_messageSettingImageView];
    
    
    _recentMessage = [[UILabel alloc]initWithFrame:CGRectMake(_senderName.frame.origin.x, _senderName.frame.origin.y+_senderName.frame.size.height+chatListCellMargin*0.5, DCDeviceWidth-_userIconImageView.frame.size.width-messageSettingWidth-4*chatListCellMargin, [UIFont systemFontOfSize:recentMessageFontSize].lineHeight)];
    
    _recentMessage.font = [UIFont systemFontOfSize:recentMessageFontSize];
    
    _recentMessage.textAlignment = NSTextAlignmentLeft;
    
    _recentMessage.textColor = [UIColor lightGrayColor];
    
    [self.contentView addSubview:_recentMessage];
    
  
   
}

-(void)setUnReadCount:(int)unReadCount
{
    if (unReadCount==0) {
        [_userIconImageView clearBadge];
    }
    else if(unReadCount==1)
    {
         [_userIconImageView showBadgeWithStyle:WBadgeStyleRedDot value:1 animationType:WBadgeAnimTypeNone];
    }
    else
    {
         [_userIconImageView showBadgeWithStyle:WBadgeStyleNumber value:unReadCount animationType:WBadgeAnimTypeNone];
    }
}


@end
